import { requestClient } from '#/api/request';
import { useCommonStore } from '#/store';

export namespace TableApi {
  export interface PageFetchParams {
    [key: string]: any;
    pageNum: number;
    pageSize: number;
  }
}

export namespace AuthApi {
  /** 登录接口参数 */
  export interface LoginParams {
    password?: string;
    username?: string;
  }

  /** 登录接口返回值 */
  export interface LoginResult {
    accessToken: string;
  }

  export interface RefreshTokenResult {
    data: string;
    status: number;
  }
}

// 一、发票获取 菜单下接口
/**
 * 一键获取发票列表接口
 */
export async function getInvoiceTaskApi(params: TableApi.PageFetchParams) {
  return await requestClient.get(`invoice/invoiceTaskPage`, {
    params: {
      ...params,
      customerId: useCommonStore().customerInfo.id as string,
    },
  });
}

// 二、进项发票 菜单下接口
/**
 * 进项发票列表
 */
export async function getInvoiceBasePageApi(params: TableApi.PageFetchParams) {
  return await requestClient.get(`invoice/invoiceBasePage`, {
    params: {
      ...params,
      customerId: useCommonStore().customerInfo.id as string,
    },
  });
}
/**
 * 发票详情
 */
export async function getInvoiceDetailApi(id: string) {
  return await requestClient.get(`invoice/${id}/detail`, {
    params: {
      customerId: useCommonStore().customerInfo.id as string,
    },
  });
}

/**
 * 新增发票接口，手动添加发票时调用。
 *
 * @param data 要添加的数据
 * @returns 请求结果
 */
export async function addInvoiceApi(data: any) {
  return requestClient.post<any>('/invoice/recordManually/add', {
    ...data,
    customerId: useCommonStore().customerInfo.id as string,
  });
}

/**
 * 修改发票接口，手动修改发票时调用。
 * @param data
 * @returns
 */
export async function updateInvoiceApi(data: any) {
  return requestClient.post<any>('/invoice/recordManually/update', {
    ...data,
    customerId: useCommonStore().customerInfo.id as string,
  });
}
